﻿using UnityEngine;

[ExecuteInEditMode]
public class FX_LookAtCamera : MonoBehaviour
{
	public Vector3 Offset = Vector3.zero;

	private Camera _target_camera;
	
	void Update()
	{
		SearchCamera();

		if( _target_camera == null )
			return;

		transform.LookAt( _target_camera.transform );
		transform.Rotate( Offset );
	}

	private void SearchCamera()
	{
		_target_camera = Camera.main;

		if( _target_camera != null )
			return;

		if( _target_camera == null && Camera.allCamerasCount > 0 )
			_target_camera = Camera.allCameras[0];
	}
}
